package com.example.demo_0828.controller;

import com.example.demo_0828.pojo.dto.AssignDTO;
import com.example.demo_0828.pojo.dto.PageQueryDTO;
import com.example.demo_0828.pojo.dto.WorkOrderDTO;
import com.example.demo_0828.pojo.entity.WorkOrder;
import com.example.demo_0828.pojo.result.PageResult;
import com.example.demo_0828.pojo.result.Result;
import com.example.demo_0828.service.WorkOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/post/order")
@Slf4j
public class WorkOrderController {

    @Autowired
    private WorkOrderService workOrderService;

    /**
     * 添加
     *
     * @param workOrderDTO
     */
    @PostMapping("/save")
    public Result save(@RequestBody WorkOrderDTO workOrderDTO) {
        log.info("添加：{}");
        workOrderService.save(workOrderDTO);
        return Result.success();
    }

    /**
     * 删除
     *
     * @param ids
     */
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("批量删除：{}");
        workOrderService.delete(ids);
        return Result.success();
    }

    /**
     * 修改
     *
     * @param workOrderDTO
     */
    @PutMapping("/update")
    public Result update(@RequestBody WorkOrderDTO workOrderDTO) {
        log.info("修改：{}");
        workOrderService.update(workOrderDTO);
        return Result.success();
    }

    /**
     * 分页查询
     *
     * @param pageQueryDTO
     * @return
     */
    @GetMapping("/search")
    public PageResult pageQuery(PageQueryDTO pageQueryDTO) {
        log.info("分页查询：{}");
        PageResult pageResult = workOrderService.pageQuery(pageQueryDTO);
        return pageResult;
    }

    /**
     * 分派
     *
     * @param assignDTO
     * @return
     */

    @PostMapping("/fenpai")
    public Result assign(AssignDTO assignDTO) {
        log.info("分派：{}");
        workOrderService.assign(assignDTO);
        return Result.success();
    }

    /**
     * 每天部门查询工单总量，超期率
     *
     * @param Month
     * @return
     */
    @GetMapping
    public Result select1(Integer Month) {
        workOrderService.select1(Month);
        return Result.success();
    }

    /**
     * 不同部门查询每天工单总量，超期率
     *
     * @param Month
     * @return
     */
    @GetMapping
    public Result select2(Integer Month) {
        workOrderService.select2(Month);
        return Result.success();
    }
}

